import UniRouteGuards from '@/js_sdk/pocky-route-gurads/lib/index.js';
import $var from './var.js';
import $skip from './skip.js';
import Vue from 'vue'
Vue.use(UniRouteGuards);
const guard = new UniRouteGuards();

guard.beforeEach((to, from, next) => {
	var toUrl = to.url;
	// console.log(toUrl)
	// console.log(to,from)
	if (toUrl) {
		var strLocal = toUrl.indexOf('?');
		if (strLocal > 0) {
			toUrl = toUrl.substr(0, strLocal);
		}
		if($var.userRoute === null && $var.commonRoute.indexOf(toUrl) == -1 && !$var.user_info){
			console.log('未登录，权限不足');
			$skip.to('login');
			return false;
		}else if($var.commonRoute.indexOf(toUrl) != -1){//公共路由 - 通过
			
		}else if(!$var.user_info){//未登录
			if($var.userRoute && $var.userRoute.indexOf(toUrl) >= 0){//会员路由 - 跳转登录
				console.log('路由权限：未登录 & 会员路由',toUrl)
				$skip.to('login');
				return false;
			}
		}
	}
	next();
});
